//
//  IllegalLanguageWarningViewController.m
//  Ai
//
//  Created by 杜超男 on 2019/3/11.
//  Copyright © 2019年 杜超男. All rights reserved.
//

#import "IllegalLanguageWarningViewController.h"
#import "FirstPositiveLanguageTableViewCell.h"
#import "IllegalLanguageWarningTableViewCell.h"
#import "Masonry.h"
#import "ClassForwardLanguageViewController.h"
#import "MonthlyReportViewController.h"

@interface IllegalLanguageWarningViewController ()<UITableViewDelegate , UITableViewDataSource>
{
    NSMutableArray *ClassNumberarr;
    NSMutableArray *LanguageNumberArr;
    //    NSInteger CompareInteger;
    NSInteger ControllerMode;
    NSInteger ArrCompareNumber;
}
@property (nonatomic , strong)UITableView *tableView;
@end

@implementation IllegalLanguageWarningViewController
-(void)viewWillAppear:(BOOL)animated{
    ControllerMode = 1;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(DetailMode) name:@"Mode" object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    ClassNumberarr = [NSMutableArray arrayWithObjects:@"10",@"10",@"10",@"10",@"10",@"10",@"10",@"10",@"10",@"10",@"10", nil];
    LanguageNumberArr = [NSMutableArray arrayWithObjects:@"10",@"10",@"10",@"10",@"10",@"10",@"10",@"10",@"10",@"10",@"10", nil];
    
    self.view.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(15, 1, self.view.frame.size.width - 30, self.view.bounds.size.height) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.tableView registerNib:[UINib nibWithNibName:@"FirstPositiveLanguageTableViewCell" bundle:nil] forCellReuseIdentifier:@"FirstPositiveLanguageTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"IllegalLanguageWarningTableViewCell" bundle:nil] forCellReuseIdentifier:@"IllegalLanguageWarningTableViewCell"];
    [self.view addSubview:self.tableView];
    self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).inset(1);
        make.bottom.mas_equalTo(0);
        
    }];
    // Do any additional setup after loading the view.
}
- (void)DetailMode{
    NSLog(@"通过点击详情的方式进入此界面");
    ControllerMode = 100;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (ControllerMode == 100) {
        NSLog(@"详情进入");
        return ClassNumberarr.count;
    }else{
        return ClassNumberarr.count + 1;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (ControllerMode == 100) {
        self.tableView.rowHeight = 200;
        IllegalLanguageWarningTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IllegalLanguageWarningTableViewCell"];
        if (!cell) {
            cell = [[IllegalLanguageWarningTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"IllegalLanguageWarningTableViewCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        if (indexPath.section == 0) {
            self.tableView.rowHeight = 150;
            FirstPositiveLanguageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FirstPositiveLanguageTableViewCell"];
            if (!cell) {
                cell = [[FirstPositiveLanguageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FirstPositiveLanguageTableViewCell"];
            }
            cell.ClassNumber.text = @"10";
            cell.NumberOfLangugeViolations.text = @"108";
            cell.LanguageNumber.text = @"违规语言总数";
            NSUserDefaults *compareUserDefaults = [[NSUserDefaults alloc] init];
            NSString *compareStr = [compareUserDefaults objectForKey:@"compare"];
            ArrCompareNumber = [compareStr integerValue];
            if (LanguageNumberArr.count == ArrCompareNumber) {
                cell.CompareNumber.text = @"持平";
                //rgba(103/255.0, 194/255.0, 86/255.0, 1)
                cell.CompareNumber.backgroundColor = [UIColor colorWithRed:103/255.0 green:194/255.0 blue:86/255.0 alpha:1];
            }else if (LanguageNumberArr.count > ArrCompareNumber){
                NSInteger Compare = LanguageNumberArr.count - ArrCompareNumber;
                cell.CompareNumber.text = [NSString stringWithFormat:@"+%ld",Compare];
                //rgba(245/255.0, 136/255.0, 29/255.0, 1)
                cell.CompareNumber.backgroundColor = [UIColor colorWithRed:245/255.0 green:136/255.0 blue:29/255.0 alpha:1];
                ArrCompareNumber = LanguageNumberArr.count;
                NSUserDefaults *comUDF = [[NSUserDefaults alloc] init];
                [comUDF setObject:[NSString stringWithFormat:@"%ld",ArrCompareNumber] forKey:@"compare"];
            }else if (LanguageNumberArr.count < ArrCompareNumber){
                NSInteger Compare = LanguageNumberArr.count - ArrCompareNumber;
                cell.CompareNumber.text = [NSString stringWithFormat:@"-%ld",Compare];
                //rgba(245/255.0, 29/255.0, 29/255.0, 1)
                cell.CompareNumber.backgroundColor = [UIColor colorWithRed:245/255.0 green:29/255.0 blue:29/255.0 alpha:1];
                ArrCompareNumber = LanguageNumberArr.count;
                NSUserDefaults *comUDF = [[NSUserDefaults alloc] init];
                [comUDF setObject:[NSString stringWithFormat:@"%ld",ArrCompareNumber] forKey:@"compare"];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else{
            self.tableView.rowHeight = 200;
            IllegalLanguageWarningTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IllegalLanguageWarningTableViewCell"];
            if (!cell) {
                cell = [[IllegalLanguageWarningTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"IllegalLanguageWarningTableViewCell"];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (ControllerMode == 100) {
        
    }else{
        if (indexPath.section == 0) {
            [self.navigationController pushViewController:[MonthlyReportViewController new] animated:YES];
        }
    }
}
- (void)DeTailBtn:(UIButton *)index{
    [self.navigationController pushViewController:[ClassForwardLanguageViewController new] animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.01)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}
//-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.01)];
//    view.backgroundColor = [UIColor clearColor];
//    return view;
//}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
